package com.langsin.crmpro.dao;

import java.util.List;

import org.hibernate.Query;

import com.langsin.crmpro.base.BaseDao;
import com.langsin.crmpro.model.CCompany;

public class CompanyDaoImpl extends BaseDao implements CompanyDao {
	
	public Integer addCompany(CCompany company) {
		return (Integer)this.getHibernateTemplate().save(company);
	}
	
	public String load4AddCompany(String todayStr){
		String queryString = "from CCompany as c where c.createTime>DATE_FORMAT(?,'%Y-%m-%d %H:%i:%s') and c.createTime<DATE_FORMAT(?,'%Y-%m-%d %H:%i:%s')";
		Query queryObject = getSession().createQuery(queryString);
		int i = 0;
		queryObject.setParameter(i++, todayStr+" 00:00:00");
		queryObject.setParameter(i++, todayStr+" 23:59:59");
		int num = queryObject.list().size();
		System.out.println(num);
		return String.valueOf(num);
	}
	
	public boolean checkCode(String code){
		String queryString = "from CCompany as c where c.code=?";
		Query queryObject = getSession().createQuery(queryString);
		int i = 0;
		queryObject.setParameter(i++, code);
		int num = queryObject.list().size();
		if(num == 0){
			return true;
		}else{
			return false;
		}
	}
	
	public List sDictionaryClassList(){
		String queryString = "from SDictionaryClass";
		Query queryObject = getSession().createQuery(queryString);
		
		return queryObject.list();
	}
	
	public List sDictionaryDetailList(){
		String queryString = "from SDictionaryDetail";
		Query queryObject = getSession().createQuery(queryString);
		
		return queryObject.list();
	}

	public List sProvinceList() {
		String queryString = "from SProvince";
		Query queryObject = getSession().createQuery(queryString);
		
		return queryObject.list();
	}

}
